package com.six.work.controller;


import com.github.pagehelper.PageInfo;
import com.six.work.entity.*;
import com.six.work.services.ResponsesServices;
import com.six.work.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("res")
public class ResponsesController {
    @Autowired
    private ResponsesServices responsesServices;

    @GetMapping("/list/{num}")
    public Result findAllResponses(@PathVariable("num") Integer num,
                                   @RequestParam(value="reasonts",defaultValue = "") String reasonts,
                                   @RequestParam(value="applicant_id",defaultValue = "0") Integer applicant_id) {
        Result result = new Result();
        PageInfo<ResView> pageInfo = responsesServices.findAllResponses(num);
        result.setObject(pageInfo);
        return result;
    }

    @GetMapping("/del")
    public Integer deleteByID(@RequestParam("response_id") Integer response_id){
        return responsesServices.DelResByID(response_id);
    }

//    @GetMapping("/update")
//    public Responses getUpdateRes(@RequestParam("response_id") Integer response_id) {
//        return responsesServices.SelectResByID(response_id);
//    }

//    @PostMapping("/update")
//    public Integer UpdateResponses(@RequestBody Responses responses){
//        return responsesservices.updateRes(responses);
//    }

    @GetMapping("/update")
    public String updateResState(@RequestParam("response_id") Integer response_id) {
        return responsesServices.updateResState(response_id);
    }

    @GetMapping("/update1")
    public String updateResState1(@RequestParam("response_id") Integer response_id) {
        return responsesServices.updateResState1(response_id);
    }

    @GetMapping("/post")
    public List<ResView> SelectResByPosID(@RequestParam("post_id") Integer post_id) {
        return responsesServices.SelectResByPosID(post_id);
    }

    @PostMapping("/add")
    public Integer InsertRes(@RequestBody Responses responses){
        return responsesServices.insertRes(responses);
    }

}
